package com.ssuu.ssuusnow.project.manage.user.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ssuu.ssuusnow.model.result.ResultVo;
import com.ssuu.ssuusnow.project.manage.user.entity.User;
import com.ssuu.ssuusnow.project.manage.user.entity.UserLogin;
import com.ssuu.ssuusnow.project.manage.user.service.impl.UserServiceImpl;
import com.ssuu.ssuusnow.utils.log.LogPrint;
import com.ssuu.ssuusnow.utils.security.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author sun
 * @since 2023-06-14
 */
@RestController
@CrossOrigin
@RequestMapping("/user")
@Api(value = "用户", tags = "用户")
@ApiSupport(author = "孙")
public class UserController {
    @Resource
    UserServiceImpl userService;

    @PostMapping("/login")
    @LogPrint("登录")
    @ApiOperation(value = "登录",notes = "备注")
    public ResultVo login(@Validated @RequestBody UserLogin userLogin) {
        return new ResultVo(userService.login(userLogin.getUsername(), userLogin.getPassword()));
    }

    @PostMapping("/add")
    @LogPrint("新增用户")
    @ApiOperation(value = "新增用户",notes = "新增用户")
    @ApiOperationSupport(ignoreParameters = {"id","createTime","updateTime","updateby","isdel"})
    public ResultVo add(@Validated @RequestBody User user) {
        return new ResultVo(userService.AddTo(user));
    }
    @PutMapping("/update")
    @LogPrint("修改用户")
    @ApiOperation(value = "修改用户",notes = "修改用户")
    @ApiOperationSupport(ignoreParameters = {"createTime","updateTime","updateby","isdel"})
    public ResultVo update(@Validated @RequestBody User user) {
        return new ResultVo(userService.UpdateTo(user));
    }
    @DeleteMapping("/del/{id}")
    @LogPrint("删除用户")
    @ApiOperation(value = "删除用户",notes = "删除用户")
    public ResultVo del(@Validated @PathVariable(value="id") Long id) {
        return new ResultVo(userService.DelTo(id));
    }
    @GetMapping("/getlist")
    @LogPrint("查询用户")
    @ApiOperation(value = "查询用户",notes = "查询用户")
    @ApiOperationSupport(ignoreParameters = {"id","createTime","updateTime","updateby","isdel"})
    public ResultVo get(User user) {
        return new ResultVo(userService.listTo(user));
    }
    @GetMapping("/getUserInfo")
    @LogPrint("查询当前登录用户")
    @ApiOperation(value = "查询当前登录用户",notes = "查询当前登录用户")
    public ResultVo getUserInfo() {
        return new ResultVo(SecurityUtils.LoginUsers());
    }
}
